
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

    <%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>
	
	<%-- 导入查询框 --%>
	<jsp:include page="search/jeSearch.jsp"></jsp:include>
	
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
		        <div class="ibox-title">
		            <h4>日记账列表</h4>
		            <div class="ibox-tools">
		            	<button id="postButton" class="btn btn-info btn-sm" type="button"><i class="fa fa-share-square-o"></i>&nbsp;&nbsp;<span class="bold">批量过账</span></button>
		                <button id="addButton" class="btn btn-success btn-sm" type="button"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">新增日记账</span></button>
		                <button id="searchButton" class="btn btn-default btn-sm btn-notcontrol" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
		            </div>
		        </div>
				<div class="ibox-content border-bottom" style="padding-bottom: 0px;">
					<div class="table-responsive">
						<table class="table table-striped table-hover table-bordered border-top">
							<thead>
								<tr>
									<th></th>
									<th width="5%">序号</th>
									<th>日记账编号</th>
									<th>日记账名称</th>
									<th>期间</th>
									<th>类型</th>
									<th>来源</th>
									<th>金额</th>
									<th>过账</th>
									<th>日记账日期</th>
									<th>制单人</th>
									<th width="5%">状态</th>
									<th width="7%">审批状态</th>
									<th width="10%">操作</th>
								</tr>
							</thead>
							<tbody>
							
							    <c:forEach items="${requestScope.gLJeHeadList}" var="data" varStatus="status">
								<tr>
									<td><input type="checkbox" class="i-checks" name="input[]"></td>
									<td class="jeHeadId" style="display: none;">${data.jeHeadId}</td>
									<td>${status.count}</td>
									<td>${data.jeHeadCode}</td>
									<td>${data.jeName}</td>
									<td>${data.periodName}</td>
									<td>${requestScope.jeTypeMap[data.jeType]}</td>
									<td>${requestScope.jeSourceMap[data.jeSource]}</td>
									<td>${data.amount}</td>
									<td>
									<c:choose>
									   <c:when test="${data.postStatus=='Y'}">
									       <span class="label label-primary">已过账</span>
									   </c:when>
									   <c:otherwise>
									       <span class="label label-danger">未过账</span>
									   </c:otherwise>
									</c:choose>
									</td>
									<td><fmt:formatDate value="${data.jeDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
									<td>${data.staffName}</td>
									<td>
									<c:choose>
									   <c:when test="${data.status=='NEW'}">
									       <span class="label label-primary">${requestScope.statusMap[data.status]}</span>
									   </c:when>
									   <c:when test="${data.status=='CONFIRM'}">
									       <span class="label label-success">${requestScope.statusMap[data.status]}</span>
									   </c:when>
									   <c:when test="${data.status=='ALTER'}">
									       <span class="label label-warning">${requestScope.statusMap[data.status]}</span>
									   </c:when>
									   <c:otherwise>
									       <span class="label label-danger">${requestScope.statusMap[data.status]}</span>
									   </c:otherwise>
									</c:choose>
									</td>
									<td>
									<c:choose>
									   <c:when test="${data.approveStatus=='UNSUBMIT'}">
									       <span class="label">${requestScope.approveStatusMap[data.approveStatus]}</span>
									   </c:when>
									   <c:when test="${data.approveStatus=='SUBMIT'}">
									       <span class="label label-primary">${requestScope.approveStatusMap[data.approveStatus]}</span>
									   </c:when>
									   <c:when test="${data.approveStatus=='APPROVE'}">
									       <span class="label label-success">${requestScope.approveStatusMap[data.approveStatus]}</span>
									   </c:when>
									   <c:when test="${data.approveStatus=='REJECT'}">
									       <span class="label label-warning">${requestScope.approveStatusMap[data.approveStatus]}</span>
									   </c:when>
									</c:choose>
									</td>
									<td>
										<div class="btn-group">
											<button class="btn-white btn btn-xs btn-notcontrol" onclick="editData(${data.jeHeadId},'${data.jeHeadCode}')"><i class="fa fa-edit"></i>&nbsp;编辑</button>&nbsp;
											
											<c:if test="${data.approveStatus!='APPROVE'&&data.approveStatus!='SUBMIT'}">
												<button class="btn-white btn btn-xs" onclick="deleteData(${data.jeHeadId},'${data.jeHeadCode}','${data.approveStatus}')"><i class="fa fa-trash"></i>&nbsp;删除</button>
											</c:if>
										</div>
									</td>
								</tr>
								</c:forEach>
								
							</tbody>
							<tfoot>
							    <%-- 导入页码 --%>
								<jsp:include page="../common/pages.jsp"></jsp:include>
							</tfoot>
						</table>
					</div>

				</div>
			</div>
		</div>
		
	</div>
</div>

<jsp:include page="pop/selectPeriodNameModalPost.jsp"></jsp:include>

<script>
	$(document).ready(function() {
		
		$('.i-checks').iCheck({
			checkboxClass : 'icheckbox_square-green',
			radioClass : 'iradio_square-green',
		});
		
		$("#addButton").click(function(){
		    window.location.href="web/gLJeHead/getGLJeHead";
		});
		
		$("#searchButton").click(function(){
		    if($("#searchDiv").css("display")=="none"){
		        $("#searchDiv").show();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
		        $("#searchButton").addClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }else{
		        $("#searchDiv").hide();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
		        $("#searchButton").removeClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }
		});
		
		//批量过账
		$("#postButton").click(function(){
			var headIds = "";
			$(".i-checks").each(function(){
				if($(this).prop("checked")){
					if(headIds==""){
						headIds = $(this).parents("tr").find("td.jeHeadId").text();
					}else{
						headIds = headIds+","+$(this).parents("tr").find("td.jeHeadId").text();
					}
				}
			});
			
			//如果没有选中
			if(headIds!=""){
				redragonJS.confirm("确认日记账过账？此操作不可逆", function(){
					window.location.href = "web/gLJeHead/postJeToGLIds?headIds="+headIds;
				});
			}else{
				$('#selectPeriodNameDiv').modal('show');
			}
			
		});
	});
	
	function editData(id, code){
		window.location.href="web/gLJeHead/getGLJeHead?jeHeadId="+id+"&jeHeadCode="+code;
	}
	
	function deleteData(id, code, approveStatus) {
		redragonJS.confirm("确认删除数据？", function(){
			window.location.href="web/gLJeHead/deleteGLJeHead?jeHeadId="+id+"&jeHeadCode="+code+"&approveStatus="+approveStatus;
		});
	}
	
</script>       